package com.wc;

import com.wc.FAKE.DB;
import com.wc.domain.Dept;
import com.wc.domain.Emp;
import com.wc.emu.Role;
import com.wc.service.EmpService;
import com.wc.service.imple.EmpServiceImpl;

import java.math.BigDecimal;
import java.util.Scanner;

/**
 * @author 鹿建文157634395376
 */


public class App {
     private final EmpService empService= new EmpServiceImpl();
     private  int login(Scanner scanner){
         System.out.println("plase put your acount");
         String username = scanner.next();
         System.out.println("plase put your password");
         String password = scanner.next();
         int empno = empService.login(username, password);
         return empno;
     }
    public static void main(String[] args) {

        App app = new App();
        Scanner scanner = new Scanner(System.in);

        int empno = 0;
        Role role = null;
        do {

             empno = app.login(scanner);
             role = app.empService.getRoleByEmpno(empno);
        } while (role==null) ;
        int op=0;
        switch (role){
            case ADMIN :
                System.out.println("andin");
                System.out.println("pleace inpt nomber to choose:1.find user's massage by empno 2.remake  user's massage by your empno 3.aduser -1.go out");
                op = scanner.nextInt();
                while (op != -1) {
                    switch (op) {
                        case 1:
                            System.out.println("find user's massage by empno");
                            System.out.println("please input empno to find");
                            int empnotofind = scanner.nextInt();
                            Emp emp = app.empService.getEmpByEmpno(empnotofind);
                            System.out.println(emp);
                            break;
                        case 2:
                            System.out.println("remake  user's massage by your empno");
                            System.out.println("please input empno to find");
                            int empnotofind2 = scanner.nextInt();
                            boolean updateRes = app.updateEmp(scanner, empnotofind2);
                            System.out.println(updateRes ? "successfull" : "sorry");
                            break;
                        case 3:
                            System.out.println("ad user");
                            break;
                        default:
                            System.out.println("what happen ,please do it again!");
                            break;
                    }
                    System.out.println("pleace inpt nomber to choose:1.find user's massage 2.remake  user's massage 3.aduser -1.go out");
                    op = scanner.nextInt();
                }
                break;
            case VIP:
                System.out.println("vip");
                break;
            case COMMON:
                System.out.println("comm");
                System.out.println("pleaese input nomber to choose : 1.query information 2.remake your information 3.find your dept information -1.go our");
                 op = scanner.nextInt();
                while (op!=-1){
                    switch (op){
                        case 1:
                            System.out.println("query information");
                            Emp emp = app.empService.getEmpByEmpno(empno);
                            System.out.println(emp);
                            break;
                        case 2:
                            System.out.println("remake your information");
                            boolean updateRes= app.updateEmp(scanner,empno) ;
                            System.out.println(updateRes?"successfull":"sorry");
                            break;
                        case 3:
                            System.out.println("find your dept information");
                            Dept dept = app.empService.getDeptByEmpno(empno);
                            System.out.println(dept);
                            break;
                        default:
                            System.out.println("what happen ,please do it again!");
                            break;
                    }
                    System.out.println("pleaese input nomber to choose : 1.query information 2.remake your information 3.find your dept information -1.go our");
                    op = scanner.nextInt();
                }
                break;
        }

        System.out.println("thaks for your use!good bye!");
        if (scanner != null) {
            scanner.close();
        }

    }

    private boolean updateEmp(Scanner scanner, int empno) {
        System.out.println("Please enter the modified dename");
        String name = scanner.next();
        System.out.println("Please enter the modified job");
        String job = scanner.next();
        System.out.println("Please enter the modified mgr");
        Integer mgr = scanner.nextInt();
        System.out.println("Please enter the modified sal");
        double sal0 = scanner.nextDouble();
        System.out.println("Please enter the modified comm");
        BigDecimal sal=new BigDecimal(sal0);
        double comm0 = scanner.nextDouble();
        BigDecimal comm=new BigDecimal(comm0);
        System.out.println("Please enter the modified deptno");
        int deptno = scanner.nextInt();
        System.out.println("Please enter the modified account");
        String account = scanner.next();
        System.out.println("Please enter the modified password");
        String password = scanner.next();
        System.out.println("Please enter the modified role");
        String role = scanner.next();
        Emp emp = Emp.builder()
                .empno(empno)
                .ename(name)
                .job(job)
                .mgr(mgr)
                .comm(comm)
                .deptno(deptno)
                .account(account)
                .password(password)
                .role(Role.getRole(role))
                .build();
//        boolean res=EmpService.updateEmp(emp);
        boolean res = empService.updateEmp(emp);
        return res;
    }


}